package cn.zebra.dev.other.module.discountsShop.service.impl;

import cn.zebra.dev.ibatis.plus.service.impl.ServiceImpl;
import cn.zebra.dev.ibatis.plus.utils.PageUtils;
import cn.zebra.dev.ibatis.plus.utils.Query;
import cn.zebra.dev.other.module.discountsShop.dao.DiscountsShopDao;
import cn.zebra.dev.other.module.discountsShop.entity.DiscountsShopEntity;
import cn.zebra.dev.other.module.discountsShop.service.DiscountsShopService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author runnable
 */
@Service
public class DiscountsShopServiceImpl extends ServiceImpl<DiscountsShopDao, DiscountsShopEntity> implements DiscountsShopService {

    @Override
    public PageUtils<DiscountsShopEntity> findPage(Map<String, Object> params) {
        QueryWrapper<DiscountsShopEntity> wrapper = new QueryWrapper<>();
        wrapper.apply(params.containsKey("shopId"),"shop_id ={0}",params.get("shopId"));
        wrapper.apply(params.containsKey("productId"),"product_id ={0}",params.get("productId"));
        IPage<DiscountsShopEntity> page = this.page(
                new Query<DiscountsShopEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils<>(page);
    }

    @Override
    public Boolean updateDiscountsById(Long id, DiscountsShopEntity discountsShopEntity) {
        return update(discountsShopEntity,"id = {0} AND delete_flag = false",id);
    }

    @Override
    public List<DiscountsShopEntity> findByIds(List<Long> discountShopIds) {
        QueryWrapper<DiscountsShopEntity> wrapper = new QueryWrapper<>();
        wrapper.in("id", discountShopIds);
        wrapper.apply("delete_flag = FALSE");
        return list(wrapper);
    }
}
